package com.aaa.service.impl;


import com.aaa.entity.ContractLease;
import com.aaa.entity.Result;
import com.aaa.mapper.ContractLeaseMapper;
import com.aaa.query.ContractQuery;
import com.aaa.service.IContractLeaseService;

import com.aaa.util.SakuraStringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author auto
 * @since 2021-01-25
 */
@Service
public class ContractLeaseServiceImpl extends ServiceImpl<ContractLeaseMapper, ContractLease> implements IContractLeaseService {

    @Autowired
    ContractLeaseMapper mapper;

    /**
     * 自有资产租出合同 查询所有
     */

    @Override
    public Result listAllPrivate() {
        List<ContractLease> map = mapper.listAllPrivate();
        return new Result(10001,"查询成功",map);
    }

    /**
     *  自有资产租出合同 添加合同
     * @param contract
     */

    @Override
    public Result addLeasePrivate(ContractLease contract) {

        int i = mapper.addLeasePrivate(contract);

        if(i>0){
            return new Result(10021,"添加成功",null);
        }
        return new Result(10022,"添加失败",null);
    }

    @Override
    public Result LeasePrivateQuery(ContractQuery query) {
        //  获取查询字段的条件
        QueryWrapper<ContractLease> queryWrapper = new QueryWrapper<>();
        //  判断字段非空 跟数据库字段作比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getContract_num()),"contract_num",query.getContract_num());
        //  判断获取字段非空 跟数据库比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getProperty_num()),"property_num",query.getProperty_num());
        //  判断获取字段非空 跟数据库比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getLessor()),"lessor",query.getLessor());

        queryWrapper.like("property_type",1);

        // 获取起始页 每页的数据
        Page<ContractLease> page = new Page(query.getPage(),query.getCount());

        // 模糊查询和分页 当成参数传入
        Page<ContractLease> map = mapper.selectPage(page, queryWrapper);

        return new Result(100001,"查询成功",map);
    }


    /**
     *  公有资产租出合同 查询所有
     */

    @Override
    public Result listAllPublic() {

        List<ContractLease> map = mapper.listAllPublic();
        return new Result(10010,"查询成功",map);
    }

    /**
     *  公有资产租出合同 添加合同
     * @param contract
     */

    @Override
    public Result addLeasePublic(ContractLease contract) {

        int i = mapper.addLeasePublic(contract);

        if(i>0){
            return new Result(10031,"添加成功",null);
        }
        return new Result(10032,"添加失败",null);
    }

    @Override
    public Result LeasePublicQuery(ContractQuery query) {
        //  获取查询字段的条件
        QueryWrapper<ContractLease> queryWrapper = new QueryWrapper<>();
        //  判断字段非空 跟数据库字段作比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getContract_num()),"contract_num",query.getContract_num());
        //  判断获取字段非空 跟数据库比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getProperty_num()),"property_num",query.getProperty_num());
        //  判断获取字段非空 跟数据库比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getLessor()),"lessor",query.getLessor());

        queryWrapper.like("property_type",2);

        // 获取起始页 每页的数据
        Page<ContractLease> page = new Page(query.getPage(),query.getCount());

        // 模糊查询和分页 当成参数传入
        Page<ContractLease> map = mapper.selectPage(page, queryWrapper);

        return new Result(100001,"查询成功",map);
    }


    /**
     *  其他资产租出合同 查询所有
     */

    @Override
    public Result listAllElse() {

        List<ContractLease> map = mapper.listAllElse();
        return new Result(10020,"查询成功,",map);
    }

    /**
     *  其他资产租出合同 添加合同
     * @param contract
     */

    @Override
    public Result addLeaseElse(ContractLease contract) {

        int i = mapper.addLeaseElse(contract);

        if(i>0){
            return new Result(10041,"添加成功",null);
        }
        return new Result(10042,"添加失败",null);
    }

    @Override
    public Result LeaseElseQuery(ContractQuery query) {
        //  获取查询字段的条件
        QueryWrapper<ContractLease> queryWrapper = new QueryWrapper<>();
        //  判断字段非空 跟数据库字段作比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getContract_num()),"contract_num",query.getContract_num());
        //  判断获取字段非空 跟数据库比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getProperty_num()),"property_num",query.getProperty_num());
        //  判断获取字段非空 跟数据库比较
        queryWrapper.like(SakuraStringUtil.isNull(query.getLessor()),"lessor",query.getLessor());

        queryWrapper.like("property_type",3);

        // 获取起始页 每页的数据
        Page<ContractLease> page = new Page(query.getPage(),query.getCount());

        // 模糊查询和分页 当成参数传入
        Page<ContractLease> map = mapper.selectPage(page, queryWrapper);

        return new Result(100001,"查询成功",map);
    }


    @Override
    public Result updateLease(ContractLease contract) {

        int i = mapper.updateLease(contract);

        if(i>0){
            return new Result(100031,"修改成功",null);
        }

        return new Result(100032,"修改失败",null);
    }


}
